import {jwtDecode} from 'jwt-decode'
// 获取token里的id
export function getId() {
        const str = jwtDecode(window.sessionStorage.token).sub
        const regex = /(\d+)/;
        const match = str.match(regex);
        const privateID = match && match[1];
        return privateID

}

// 获取token的角色
export function getRole() {
  const decodedToken = jwtDecode(window.sessionStorage.token);
  if (decodedToken.sub) {
    const regex =  '\\{ROLE_KEY=(\\w+)}';
    const match = decodedToken.sub.match(regex);
    if (match) {
      return match[1]; // 匹配到的字符串就是 ROLE_KEY 的值
    } else {
      return null;
    }
  } else {
    return null;
  }
}